/**
 * @name AddTodo
 * @desc 新增待办
 * @author darcrand
 * @version 2018-10-14
 */

import React, { Component } from "react"
import "./styles.css"

class AddTodo extends Component {
    static defaultProps = {
        handleAddTodoItem: id => {}
    }

    createItem = e => {
        if (e.keyCode !== 13 || !e.target.value.trim()) {
            return
        }
        const val = e.target.value
        this.props.handleAddTodoItem({ id: new Date().getTime(), message: val, status: false })
        e.target.value = ""
    }

    render() {
        return <input type="text" className="add-todo" placeholder="input then hit enter" maxLength={50} onKeyDown={this.createItem} />
    }
}

export default AddTodo
